/*
 * Copyright (c) 2006-2021, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2024-05-12     PC       the first version
 */

#include <rtthread.h>
#include <stdlib.h>

rt_bool_t leap(rt_uint32_t year)
{
    if(year%4)
    {
        return RT_FALSE;
    }
    if(!(year%400))
    {
        return RT_TRUE;
    }
    if(!(year%100) && (year%400))
    {
        return RT_FALSE;
    }
    return RT_TRUE;
}

static int leap_cmd(int argc, char **argv)
{
    if(2 > argc)
    {
        rt_kprintf("usage:\n");
        rt_kprintf("%s year \n\n",argv[0]);
        return -RT_EINVAL;
    }
    //
    rt_uint32_t year = atoi(argv[1]);
    if(RT_TRUE == leap(year))
    {
        rt_kprintf("%d is a leap year\n", year);
    }
    else
    {
        rt_kprintf("%d isn't a leap year !!\n", year);
    }
    return RT_EOK;
}
MSH_CMD_EXPORT_ALIAS(leap_cmd, leap, leap judgment);


